using AutoMapper;
using Common.Communal;
using MediatR;
using Product.API.ISerivces.ProcessRoute;
using Product.API.Write.Applications.Commands.ProcessRoute;

namespace Product.API.Write.Applications.CommandHandlers.ProcessRoute
{
    /// <summary>
    /// 工艺路线删除命令处理
    /// </summary>
    public class DeleteProcessRouteCommandHandler : IRequestHandler<DeleteProcessRouteCommand, ApiResult<int>>
    {
        /// <summary>
        /// 工序流程服务
        /// </summary>
        private readonly IProcessRouteSerivce processRouteSerivce;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="processRouteSerivce">工序流程服务</param>
        public DeleteProcessRouteCommandHandler(IProcessRouteSerivce processRouteSerivce)
        {
            this.processRouteSerivce = processRouteSerivce;
        }

        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回任务</returns>
        public async Task<ApiResult<int>> Handle(DeleteProcessRouteCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code = EnumCode.Ok;
            result.Message = EnumCode.Ok.ToString();

            int data = await processRouteSerivce.DeleteProcessRoute(request.Id);
            result.Data = data;

            return await Task.FromResult(result);
        }
    }
}


